{template 'common/header-storex'}
<div class="wn-main">
	<div class="wn-main__head">商品管理</div>
	<div class="wn-main__content">
		<div class="wn-tabs">
			<div class="wn-tabs__item {if $op == 'display'}wn-tabs__item--active{/if}">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'display', 'storeid' => $_GPC['storeid']))}">商品列表</a>
			</div>
			{if $store['store_type'] == STORE_TYPE_HOTEL}
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_room_status', array('storeid' => $_GPC['storeid']))}">维护房量/房态</a>
			</div>
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_room_price', array('storeid' => $_GPC['storeid']))}">维护房价</a>
			</div>
			{/if}
			{if $store['store_type'] != STORE_TYPE_HOTEL}
			<div class="wn-tabs__item">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_tagmanage', array('storeid' => $_GPC['storeid']))}">标签管理</a>
			</div>
			{/if}
			<div class="wn-tabs__item {if $op == 'recycle'}wn-tabs__item--active{/if}">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'recycle', 'storeid' => $_GPC['storeid']))}">商品回收站</a>
			</div>
		</div>
		<div class="wn-main__search clearfix">
			<div class="wn-main__search__form" style="width: 600px">
				<form action="./index.php" method="get" class="form-horizontal from" role="form">
					<input type="hidden" name="c" value="site" />
					<input type="hidden" name="a" value="entry" />
					<input type="hidden" name="m" value="wn_storex" />
					<input type="hidden" name="do" value="shop_goodsmanage" />
					<input type="hidden" name="storeid" value="{$storeid}">
					<div class="form-group">
						<div class="col-sm-6">
							<select name="category_id" class="form-control input-medium">
								<option value="">全部分类</option>
								{loop $category_set $class}
									<option value="{$class['id']}" {if $category_id == $class['id']} selected="selected" {/if}>{$class['name']}</option>
									{if !empty($class['sub_class'])}
										{loop $class['sub_class'] $sub_class}
											<option value="{$sub_class['id']}" {if $category_id == $sub_class['id']} selected="selected" {/if}>----{$sub_class['name']}</option>
										{/loop}
									{/if}
								{/loop}
							</select>
						</div>
						<div class="col-sm-4">
							<div class="input-group">
								<input class="form-control" name="title" placeholder="请输入商品名称" id="" type="text" value="{$_GPC['title']}">
								<div class="input-group-btn"><button class="btn btn-default"><i class="fa fa-search"></i> </button></div>
							</div>
						</div>
					</div>
				</form>
			</div>
			{if $op == 'display'}
			<div class="wn-main__search__action">
				<a href="{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'edit', 'storeid' => $storeid));}" id="add_coupon" class="btn btn-primary we7-padding-horizontal">+添加商品</a>
			</div>
			{/if}
		</div>
		{if $store['store_type'] != STORE_TYPE_HOTEL}
		{template 'store/goodsmanage_common_table'}
		{else}
		{template 'store/goodsmanage_hotel_table'}
		{/if}
	</div>
</div>

<div class="modal fade" id="tag-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">标签选择</h4>
			</div>
			<div class="modal-body clearfix form-horizontal">
				<input name="goodsid" value="" type="hidden">
				{if !empty($tags)}
				{loop $tags $tid $info}
				<button type="button" class="btn btn-default tag_check" data-tid="{$tid}">{$info['title']}</button>
				{/loop}
				{else}
				暂无标签
				{/if}
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="entry-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">商品入口查看</h4>
			</div>
			<div class="modal-body clearfix form-horizontal">
				<div role="tabpanel" class="tab-pane active text-center" id="put-qrcode">
					<div class="alert alert-info text-left">
						扫描二维码或复制链接
					</div>
					<div class="js-qrcode-block" style="margin:50px 0 50px 0"></div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 control-label"><span class="text-danger"></span> 入口链接：</label>
					<div class="col-sm-10 col-xs-12">
						<input class="js-url-show form-control" readonly>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$(function() {
		require(['jquery.qrcode'], function(){
			$('.js-qrcode-entry').click(function() {
				id = $(this).data('id');
				if (id) {
					$.post("{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'qrcode_entry', 'storeid' => $_GPC['storeid']))}", {id : id}, function(data) {
						data = $.parseJSON(data);
						if (data.message.errno == 0) {
							$('.js-qrcode-block').html('').qrcode({
								render: 'canvas',
								width: 300,
								height: 300,
								text: data.message.message,
							});
							$('.js-url-show').val(data.message.message);
							$('#entry-modal').modal('show');
						} else {
							util.message(data.message.message);
							$('#entry-modal').modal('hide');
						}
					});
				}
			});
		});
		
		$('.tag_select_mode').click(function() {
			var id = $(this).data('id');
			$('input[name=goodsid]').val(id);
			$('#tag-modal').modal('show');
		});
		
		$('.tag_check').click(function() {
			var tid = $(this).data('tid');
			var goodsid = $('input[name=goodsid]').val();
			$.post("{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'set_tag', 'storeid' => $storeid))}", {tid : tid, goodsid : goodsid},function(data) {
				if (data.message.errno ==0) {
					util.message(data.message.message, 'refresh', 'success');
					return;
				} else {
					util.message(data.message.message);
					return;
				}
			}, 'json');
			$('#tag-modal').modal('hide');
		});
		
		$('.check_all').click(function() {
			var checked = $(this).get(0).checked;
			$('input[type=checkbox]').prop("checked",checked);
		});
		$('input[name=recycleall]').click(function() {
			var check = $("input[name='check']:checked");
			if (check.length < 1) {
				util.message('请选择要放入回收站的商品!');
				return;
			}
			if (confirm("确认要回收选择的商品?")) {
				var id = new Array();
				check.each(function(i) {
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'recycleall', 'storeid' => $storeid))}", {idArr : id}, function(data) {
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
						return;
					} else {
						util.message(data.message.message);
						return;
					}
				},'json');
			}
		});
		$('input[name=renewall]').click(function() {
			var check = $("input[name='check']:checked");
			if (check.length < 1) {
				util.message('请选择要恢复的商品!');
				return;
			}
			if (confirm("确认要回收选择的记录?")) {
				var id = new Array();
				check.each(function(i) {
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'renewall', 'storeid' => $storeid))}", {idArr : id}, function(data) {
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
						return;
					} else {
						util.message(data.message.message);
						return;
					}
				},'json');
			}
		});
		$('input[name=deleteall]').click(function() {
			var check = $("input[name='check']:checked");
			if (check.length < 1) {
				util.message('请选择要放入回收站的商品!');
				return;
			}
			if (confirm("确认要回收选择的商品?")) {
				var id = new Array();
				check.each(function(i) {
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_goodsmanage', array('op' => 'deleteall', 'storeid' => $storeid))}", {idArr : id}, function(data) {
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
						return;
					} else {
						util.message(data.message.message);
						return;
					}
				},'json');
			}
		});
		$('.edit_all').click(function() {
			var name = $(this).attr('name');
			var check = $('input:checked');
			if (check.length<1) {
				util.message('请选择要操作的商品!');
			} else {
				var id = new Array();
				check.each(function(i) {
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_goodsmanage',array('op' => 'showall', 'storeid' => $storeid))}", {idArr:id, show_name:name},function(data) {
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
					} else {
						util.message(data.message.message);
					}
				},'json');
			}
		});
	});
	
	function drop_confirm(msg, url) {
		if (confirm(msg)) {
			window.location = url;
		}
	}
</script>
{template 'common/footer-storex'}